#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Módulos 
import sys, gtk, pygame, utils, objetos
from pygame.locals import *
# Constantes
 
# Clases
# ---------------------------------------------------------------------

class Beto(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = utils.load_image("images/c0_beto1.png", True)
        self.rect = self.image.get_rect()
        self.rect.centerx = 650*utils.RES
        self.rect.centery = 320*utils.RES

# ---------------------------------------------------------------------
 
# Funciones
# ---------------------------------------------------------------------
 
 
# ---------------------------------------------------------------------
 
def dibujar(screen,cursor_picture, clock):
	
	salir = 0
	background_image = utils.load_image('images/fondo0_1.jpg')
	titulo_clases, titulo_clases_rect = utils.texto_titulo("Elija una clase para empezar!", 430*utils.RES,160*utils.RES,(255,0,0))
	clases_habilitadas = (True,True,True,True,True,True,True)
    
	clase1  = objetos.Boton_menu("images/menu_boton1.png", 260*utils.RES, 50*utils.RES)
	clase2  = objetos.Boton_menu("images/menu_boton2.png", 260*utils.RES, 120*utils.RES)
	clase3  = objetos.Boton_menu("images/menu_boton3.png", 260*utils.RES, 190*utils.RES)
	clase4  = objetos.Boton_menu("images/menu_boton4.png", 260*utils.RES, 260*utils.RES)
	clase5  = objetos.Boton_menu("images/menu_boton5.png", 260*utils.RES, 330*utils.RES)
	clase6  = objetos.Boton_menu("images/menu_boton6.png", 260*utils.RES, 400*utils.RES)
	clase7  = objetos.Boton_menu("images/menu_boton7.png", 260*utils.RES, 470*utils.RES)
	encuesta, encuesta_rect = utils.texto_subtitulo("Encuesta", 440*utils.RES, 330*utils.RES)
	encuesta2, encuesta2_rect = utils.texto_subtitulo("Final", 440*utils.RES, 350*utils.RES)
    
	beto = Beto()
	show_dialog = False
	voz_beto = pygame.mixer.Sound("sounds/0_2a.ogg") 
	transicion = pygame.mixer.Sound("sounds/transicion.ogg") 
	#voz_beto.set_volume(0.5)       
	dialog = utils.load_image('images/c0_dialogo_menu.png', True)
	frame = 0

	while salir == 0:
		
		# Pump GTK messages.
		while gtk.events_pending():
		   gtk.main_iteration()
		
		for eventos in pygame.event.get():
			if eventos.type == QUIT:
				sys.exit(0)
			elif eventos.type == pygame.VIDEORESIZE:
				pygame.display.set_mode(eventos.size, pygame.RESIZABLE)
			elif eventos.type == MOUSEBUTTONDOWN:
				if clase1.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 1
					clase1.sonido.play()

				elif clase2.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 2
					clase2.sonido.play()

				elif clase3.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 3
					clase3.sonido.play()	

				elif clase4.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 4
					clase3.sonido.play()

				elif clase5.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 5
					clase5.sonido.play()	
				
				elif encuesta_rect.collidepoint(pygame.mouse.get_pos()):
					salir = 8
					
				elif encuesta2_rect.collidepoint(pygame.mouse.get_pos()):
					salir = 8	
				
				elif clase6.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 6
					clase6.sonido.play()		

				elif clase7.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 7
					clase7.sonido.play()	
				

				elif beto.rect.collidepoint(pygame.mouse.get_pos()):	
					voz_beto.stop()
					voz_beto.play()
					
		screen.blit(background_image, (0, 0))
		#screen.blit(titulo_clases, titulo_clases_rect)
		if frame % 10 == 0 and 100 > frame:
			transicion.play()
		if frame > 10:			
			screen.blit(clase1.image, clase1.rect)
		if frame > 20:			
			screen.blit(clase2.image, clase2.rect)
		if frame > 30:					
			screen.blit(clase3.image, clase3.rect)
		if frame > 40:					
			screen.blit(clase4.image, clase4.rect)
		if frame > 50:					
			screen.blit(clase5.image, clase5.rect)
		if frame > 60:					
			screen.blit(clase6.image, clase6.rect)
		if frame > 70:					
			screen.blit(clase7.image, clase7.rect)
		if frame > 80:					
			screen.blit(beto.image, beto.rect)
		if frame > 100:					
			screen.blit(dialog, (int(350*utils.RES), int(40*utils.RES)))
		if frame > 80:				
			if clases_habilitadas[5]:
				screen.blit(encuesta,encuesta_rect)	
				screen.blit(encuesta2,encuesta2_rect)	
		if frame == 101:	
			voz_beto.play()
		screen.blit(cursor_picture, pygame.mouse.get_pos())	
		pygame.display.flip()
        	 
		# Try to stay at 30 FPS
		clock.tick(30)
		frame = frame + 1

	voz_beto.stop()
	return salir


# This function is called when the game is run directly from the command line:
# ./TestGame.py 
def main():
	
	pygame.init()
	screen = pygame.display.set_mode((int(800*utils.RES), int(520*utils.RES)), pygame.RESIZABLE) #pygame.display.get_surface() #

	# Fake a Sugar cursor for the pyGame canvas area
	pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0))
	cursor_picture = pygame.image.load('images/standardcursor.png')
	cursor_picture.convert_alpha() 
	clock = pygame.time.Clock()
	dibujar(screen,cursor_picture,clock)

if __name__ == '__main__':
   main()
